package com.taxshare.seller.controller;

import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.response.beans.Response;
import com.taxshare.seller.entity.SellerInvoiceEntity;
import com.taxshare.seller.service.InvoicedService;
import com.taxshare.seller.view.dto.InvoicedDTO;
import com.taxshare.seller.view.dto.RedInvoiceInfoFirstDTO;
import com.taxshare.seller.view.dto.SynchronizeInvoiceDTO;
import com.taxshare.seller.view.vo.SellerInvoiceRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

/**
 * @author YANG
 * @date 2021/3/25
 */
@RestController
@RequestMapping("/sellerInvoice")
@Api(tags = "已开发票管理")
public class InvoicedController {

    @Autowired
    InvoicedService invoicedService;

    @PostMapping("/query")
    @ApiOperation(value = "已开发票查询", notes = "已开发票管理")
    public Response<List<SellerInvoiceEntity>> invoicedQuery(@RequestBody PageRequest<InvoicedDTO> query) {
        return invoicedService.invoicedQuery(query);
    }

    @GetMapping("/export")
    @ApiOperation(value = "已开发票导出", notes = "已开发票管理")
    public void exportInvoiced(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
        invoicedService.exportInvoiced(request, httpServletResponse);
    }

    @GetMapping("/exportDetail")
    @ApiOperation(value = "已开发明细导出", notes = "已开发票管理")
    public void exportDetail(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
        invoicedService.exportDetail(request, httpServletResponse);
    }
    @GetMapping("/exportCarDetail")
    @ApiOperation(value = "机动车已开发票明细导出", notes = "已开发票管理")
    public void exportCarDetail(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
        invoicedService.exportCarDetail(request, httpServletResponse);
    }

    @PostMapping("/syncInvoice")
    @ApiOperation(value = "同步已开发票", notes = "已开发票管理")
    public Response syncInvoice(@RequestBody SynchronizeInvoiceDTO synchronizeInvoiceDTO) throws UnsupportedEncodingException {
        return invoicedService.syncInvoice(synchronizeInvoiceDTO);
    }

    @PostMapping("/invoiceCancel")
    @ApiOperation(value = "已开发票作废", notes = "已开发票管理")
    public Response invoiceCancel(@RequestBody InvoicedDTO invoicedDTO) throws UnsupportedEncodingException {
        return invoicedService.invoiceCancel(invoicedDTO);
    }

    @GetMapping("/makeRedCommonInvoice")
    @ApiOperation(value = "普票红冲", notes = "已开发票")
    public Response makeRedCommonInvoice(@RequestParam String serialNo) {
        return invoicedService.makeRedCommonInvoice(serialNo);
    }

    @GetMapping("/carMakeRedCommonInvoice")
    @ApiOperation(value = "机动车普票红冲", notes = "已开发票")
    public Response carMakeRedCommonInvoice(@RequestParam String serialNo) {
        return invoicedService.carMakeRedCommonInvoice(serialNo);
    }


    @PostMapping("/reqRedInvoiceInfoFirst")
    @ApiOperation(value = "红字信息表申请",notes = "已开发票")
    public Response reqRedInvoiceInfoFirst(@RequestBody RedInvoiceInfoFirstDTO redInvoiceInfoFirstDTO){
        return invoicedService.reqRedInvoiceInfoFirst(redInvoiceInfoFirstDTO);
    }

    @PostMapping("/reqRedInvoiceInfoTwo")
    @ApiOperation(value = "红字信息表申请开始提交申请",notes = "已开发票")
    public Response reqRedInvoiceInfoTwo(@RequestBody SellerInvoiceRVO parames) {
        return invoicedService.reqRedInvoiceInfoTwo(parames);
    }

    @PostMapping("/downLoadPdf")
    @ApiOperation(value = "pdf下载",notes = "已开发票")
    public Response downLoadPdf(@RequestBody InvoicedDTO dto){
        return invoicedService.downLoadPdf(dto);
    }


    @PostMapping("/makeInvoice")
    @ResponseBody
    @ApiOperation(value = "批量开票",notes = "待开发票管理")
    public Response makeInvoice(@RequestBody List<String> serialNos){
        return invoicedService.makeInvoice(serialNos);
    }


    @PostMapping("/sqHcInvoice")
    @ResponseBody
    @ApiOperation(value = "整体红冲申请",notes = "待开发票管理")
    public Response sqHcInvoice(@RequestParam Map<String, Object> param){
        return invoicedService.sqHcInvoice(param);
    }

    @PostMapping("/bfSqHcInvoice")
    @ResponseBody
    @ApiOperation(value = "部分红冲申请",notes = "待开发票管理")
    public Response bfSqHcInvoice(@RequestBody SellerInvoiceEntity sellerInvoiceEntity){
        return invoicedService.bfSqHcInvoice(sellerInvoiceEntity);
    }



    @PostMapping("/hcRedInvoice")
    @ResponseBody
    @ApiOperation(value = "数电红冲", notes = "待开发票管理")
    public Response hcRedInvoice(@RequestParam Map<String, Object> param) {
        return invoicedService.hcRedInvoice(param);
    }


    @PostMapping("/getInvoice")
    @ResponseBody
    @ApiOperation(value = "获取发票信息", notes = "已开发票管理")
    public Response getInvoice(@RequestParam Map<String, Object> param) {
        return invoicedService.getInvoice(param);
    }


}
